// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-6-15 11:59:13
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Common_qry_QueryMap.java

package com.creawor.imei.base;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.cfg.Configuration;

import org.apache.log4j.Logger;

import report.ConnectSqlServer;

// Referenced classes of package com.creawor.imei.base:
//            AbsQueryMap, QueryBean

public class Common_qry_QueryMap extends AbsQueryMap
{
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(Common_qry_QueryMap.class);

    public Common_qry_QueryMap()
        throws HibernateException
    {
        initSession();
//        Configuration
    }

    public ArrayList findAll_sql(String sql)
        throws HibernateException
    {
		if (logger.isDebugEnabled()) {
			logger.debug("findAll_sql(String) - start");
		}

        QueryBean qb = new QueryBean();
        qb.conn = session.connection();
        qb.connect();
        qb.SQLstr = sql;
        qb.executeQuery();
        totalrow = qb.record_count;
		ArrayList returnArrayList = qb.findAll_page(pageno.intValue(), pagesize
				.intValue());
		if (logger.isDebugEnabled()) {
			logger.debug("findAll_sql(String) - end");
		}
        return returnArrayList;
    }

    public ArrayList findAll_sql(String sql, int pagesize)
        throws HibernateException
    {
		if (logger.isDebugEnabled()) {
			logger.debug("findAll_sql(String, int) - start");
		}

        QueryBean qb = new QueryBean();
        qb.conn = session.connection();
        qb.connect();
        qb.SQLstr = sql;
        qb.executeQuery();
        totalrow = qb.record_count;
		ArrayList returnArrayList = qb.findAll_page(pageno.intValue(), pagesize);
		if (logger.isDebugEnabled()) {
			logger.debug("findAll_sql(String, int) - end");
		}
        return returnArrayList;
    }

    public ArrayList findAll(String sql)
        throws HibernateException
    {
		if (logger.isDebugEnabled()) {
			logger.debug("findAll(String) - start");
		}
		if(logger.isInfoEnabled()){
			logger.info("sql="+sql);
		}

  		if(null==sql)return null;
  		Session session = null;
  		Configuration conf = null;
  		ArrayList rsList=new ArrayList();
  		java.sql.Connection con=null;
  		try{
  			/*SessionFactory sf = (new Configuration()).configure().buildSessionFactory();
  	        session = sf.openSession();
  	        java.sql.Connection con=session.connection();*/
  			
  					con=ConnectSqlServer.getConnection();
  	        ResultSet rs=con.createStatement().executeQuery(sql);
  	        ResultSetMetaData rsmd= rs.getMetaData();
  	        int colNum=rsmd.getColumnCount();
  	        Map row=null;
  	        String colName=null;
  	        while(rs.next()){
  	        	row=new HashMap();
  	        	for(int i=1;i<=colNum;i++){
  	        		colName=rsmd.getColumnName(i);
  	        		row.put(colName.toLowerCase(),rs.getString(colName));
  	        	}
  	        	rsList.add(row);
  	        }
  	        rs.close();
  	        con.close();
  	        
  		}catch(Exception e){
			logger.error("findAll(String)", e);

  			e.printStackTrace();
  		}finally{
  			try{con.close();}catch(Exception e){
  			}
  		}

			if (logger.isDebugEnabled()) {
			logger.debug("findAll(String) - end");
		}
          return rsList;
  	
        /*QueryBean qb = new QueryBean();
        qb.conn = session.connection();
        qb.connect();
        qb.SQLstr = sql;
        qb.executeQuery();
        totalrow = qb.record_count;
        return qb.findAll_page(1, 3000);*/
        
        
    }
    
    public void executeSql(String sql)
    throws HibernateException
    {

		//if(null==sql)return null;
		/*Session session = null;
		Configuration conf = null;
		ArrayList rsList=new ArrayList();
		ResultSet rs=null;*/
		java.sql.Statement stmt=null;
		java.sql.Connection con=null;
		try{
			/*SessionFactory sf = (new Configuration()).configure().buildSessionFactory();
	        session = sf.openSession();
	        java.sql.Connection con=session.connection();*/
			
					con=ConnectSqlServer.getConnection();
					stmt = con.createStatement(); 
	        //rs=con.createStatement().executeQuery(sql);
	        stmt.executeUpdate(sql);
	        /*ResultSetMetaData rsmd= rs.getMetaData();
	        int colNum=rsmd.getColumnCount();
	        Map row=null;
	        String colName=null;
	        while(rs.next()){
	        	row=new HashMap();
	        	for(int i=1;i<=colNum;i++){
	        		colName=rsmd.getColumnName(i);
	        		row.put(colName.toLowerCase(),rs.getString(colName));
	        	}
	        	rsList.add(row);
	        }*/
	      //  rs.close();
	        con.close();
	        
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{con.close();}catch(Exception e){}
		}
     
}

    public void execSql(String sql)
        throws HibernateException
    {
		if (logger.isDebugEnabled()) {
			logger.debug("execSql(String) - start");
		}

        QueryBean qb = new QueryBean();
        qb.conn = session.connection();
        qb.connect();
        qb.SQLstr = sql;
        try
        {
            qb.execUpdate(sql);
        }
        catch(SQLException e)
        {
			logger.error("execSql(String)", e);

            e.printStackTrace();
        }

			if (logger.isDebugEnabled()) {
			logger.debug("execSql(String) - end");
		}
    }
    
    public static void main(String[] args){
    	try {
				Common_qry_QueryMap query=new Common_qry_QueryMap();
				List ls=query.findAll("select TABLE_NAME,FIELD_NAME,FIELD_MEMO from CICF_FIELD_INFO group by TABLE_NAME,FIELD_NAME,FIELD_MEMO");
				System.out.println(ls.toString());
			} catch (HibernateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    }
}